import axios from 'axios';
import { PageParams, PageResult } from '@/types/page';
import { Data } from '@arco-design/web-vue/es/_utils/types';
import type { SelectOptionData } from '@arco-design/web-vue/es/select/interface';

export interface MenuShow {
	id : number,
	menuName : string
}

export interface QueryMenuDto {
	menuId ?: number,
	menuName ?: string,
	parentId : number
}

export interface MenuInfo {
	id ?: number,
	status ?: number,
	updateTime ?: Data,
	parentId ?: number,
	isParent ?: number,
	menuCode ?: string,
	menuName ?: string,
	url ?: string
}

export interface QueryRoleDto {
	menuId ?: number,
	roleId ?: string,
	roleName ?: string
}



export interface UpdateRoleMenuDto {
	roleId : number,
	menuIds : string
}

export interface RoleInfo {
	id? : number,
	status? : number,
	updateTime? : Data,
	roleName : string,
	roleCode : string,
	description : string,
	type : number
}

export interface MenuTree {
	title : string,
	key : number,
	disabled : boolean,
	chiledren : MenuTree[]
}


export function getParentMenu() {
	return axios.get<MenuShow[]>('/participant/close/resource/parent-menu');
}

export function getSonMenu() {
	return axios.get<MenuShow[]>('/participant/close/resource/son-menu');
}

export function searchMenuByPage(params : PageParams, data : QueryMenuDto) {
	return axios.post<PageResult<MenuInfo>>(`/participant/close/resource/search-menu?current=${params.current}&pageSize=${params.pageSize}`, data);
}

export function addMenu(data : MenuInfo) {
	return axios.post('/participant/close/resource/add-menu', data);
}

export function delMenu(params : { menuId : number }) {
	return axios.get('/participant/close/resource/del-menu', { params });
}

export function searchRoleByPage(params : PageParams, data : QueryRoleDto) {
	return axios.post<PageResult<RoleInfo>>(`/participant/close/resource/search-role?current=${params.current}&pageSize=${params.pageSize}`, data);
}

export function addRole(data : RoleInfo) {
	return axios.post('/participant/close/resource/add-role', data);
}

export function delRole(params : { roleId : number, type : number }) {
	return axios.get('/participant/close/resource/del-role', { params });
}

export function getRoleMenu(params : { roleId : number }) {
	return axios.get<number[]>('/participant/close/resource/get-menu-role', { params });
}

export function updateRoleMenu(params : UpdateRoleMenuDto) {
	return axios.get('/participant/close/resource/update-menu-role', { params });
}

export function getTreeMenu() {
	return axios.get<SelectOptionData[]>('/participant/close/resource/tree-menu');
}